package com.atguigu.srb.core.controller.admin;


import com.atguigu.srb.common.result.R;
import com.atguigu.srb.core.enums.LendStatusEnum;
import com.atguigu.srb.core.pojo.entity.Borrower;
import com.atguigu.srb.core.pojo.entity.Lend;
import com.atguigu.srb.core.service.BorrowerService;
import com.atguigu.srb.core.service.DictService;
import com.atguigu.srb.core.service.LendService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 标的准备表 前端控制器
 * </p>
 *
 * @author LiLi
 * @since 2021-09-23
 */
@RestController
@RequestMapping("/admin/core/lend")
@Api("后台管理标的接口")
@Slf4j
public class AdminLendController {
    @Autowired
    LendService lendService;
    @Autowired
    DictService dictService;
    @ApiOperation("标的集合")
    @GetMapping("list")
    public R list(){
        List<Lend> list = lendService.selectList();
        for (Lend lend :
                list) {
            lend.getParam().put("returnMethod", dictService.getNameByParentDictCodeAndValue("returnMethod",lend.getReturnMethod()));
            lend.getParam().put("status", LendStatusEnum.getMsgByStatus(lend.getStatus()));

        }
        return R.ok().data("list",list);
    }
    @ApiOperation("标的详情列表")
    @GetMapping("/show/{id}")
    public R show(@PathVariable("id") Long id){
        System.out.println(id);
        Map<String,Object> lendDetail = lendService.getLendDetail(id);
        return R.ok().data("lendDetail",lendDetail);
    }
}

